;
(function () {
  new Vue({
    el: '#config-complete',
    data: {
      wrokList: [],
      offOn: [{
        name: '开启',
        code: '1'
      }, {
        name: '关闭',
        code: '0'
      }],
      options1: [{
        name: '是',
        code: 'Y'
      }, {
        name: '否',
        code: 'N'
      }],
      options2: [{
        name: '开启',
        code: 'Y'
      }, {
        name: '关闭',
        code: 'N'
      }],

      options3: [],

      selected1: [],
      selected2: [],
      selected3: [],
      workFlag: false,
      workFlag1: false,
      workFlag2: false,
      quanxian: JSON.parse(localStorage.getItem('permissions')),
      customerDict: [],
      active: false,

      rentConfig: false,
      rentConfigData: '',
      rentConfigCode: '',

      rentConfigEnd: false,
      rentConfigDataEnd: '',
      rentConfigCodeEnd: ''
    },
    methods: {
      //去流失客户页面
      toLsCustomer() {
        hlUrlUtil.goTo('lscustomerConfig', {
          ddtab: true
        })
      },
      //获取账单提交流程开启
      getbillflow() {
        hlhttp.get({
          url: 'configure/bill_bpm_config/dict',
          success: res => {
            this.selected2 = [res.open_flag]
            if (!res.dict_property) return
            let arr = JSON.parse(res.dict_property).billBpmValue
            arr.map(item => {
              item.code = item.dictCode
              item.name = item.dictName
              item.openFlag = [item.openFlag]
              if (item.openFlag == 'Y') {
                this.selected3.push(item.code)
              }
            })
            console.log(arr)
            this.options3 = arr
          }
        })
      },
      selectTbillBpmConfig() {
        let arr = []
        this.options3.map((item, index) => {
          let obj = {
            dictCode: item.dictCode,
            dictName: item.dictName,
          }
          if (this.selected3.indexOf(item.code) != -1) {
            obj.openFlag = 'Y'
          } else {
            obj.openFlag = 'N'
          }
          arr.push(obj)
        })
        let newObj = JSON.stringify({
          billBpmValue: arr
        })
        hlhttp.put({
          url: 'configure/bill_bpm_config/dict',
          data: {
            open_flag: this.selected2 + '',
            dict_property: newObj
          },
          success: res => {}
        })
      },
      // 获取意向工作流配置
      geTintentBpmConfig() {
        hlhttp.get({
          url: 'configure/intent_bpm_config/dict',
          success: res => {
            this.selected1 = [res.open_flag]
          }
        })
      },

      selectTintentBpmConfig() {
        hlhttp.put({
          url: 'configure/intent_bpm_config/dict',
          data: {
            open_flag: this.selected1 + ''
          },
          success: res => {}
        })
      },

      switchActive(val) {
        this.active = val
        this.setCostomer()
      },

      // 获取客户数据隔离字典
      getCostomer() {
        hlhttp.get({
          url: 'configure/dict',
          data: {
            module_code: 'ZHSH',
            config_name: 'ZS_CUSTOMER_DATA_ISOLATION'
          },
          success: (res) => {
            this.customerDict = res
            this.active = res[0].dictName == 'N' ? false : true
          }
        })
      },
      setCostomer() {
        let data = {
          module_code: 'ZHSH',
          config_name: 'ZS_CUSTOMER_DATA_ISOLATION',
          dict_code: this.customerDict[0].dictCode,
          value: this.active ? 'Y' : 'N'
        }
        hlhttp.put({
          url: 'configure/user_defined_dict',
          data: data,
          success: (res) => {
            this.getCostomer()
          }
        })
      },



      toCustomFeilds() {
        hlUrlUtil.goTo('lcCutomFields', {
          ddtab: true
        })
      },
      toConfigPage1() {
        hlUrlUtil.goTo('visitorConfig', {
          ddtab: true
        })
      },
      toConfigPage2() {
        hlUrlUtil.goTo('intentionalArea', {
          ddtab: true
        })
      },
      nmslToDebiLevel() {
        hlUrlUtil.goTo('debiLevel', {
          ddtab: true
        })
      },
      nmslToDebiType() {
        hlUrlUtil.goTo('debiType', {
          ddtab: true
        })
      },
      goTo_M_channel: function () {
        hlUrlUtil.goTo('marketChannel', {
          ddtab: true
        })
      },
      goTo_M_process: function () {
        hlUrlUtil.goTo('marketProcess', {
          ddtab: true
        })
      },
      goTo_M_custom: function () {
        hlUrlUtil.goTo('lcCutomFields', {
          ddtab: true,
          module: 'MARKET_EXPANSION_PROJECT'
        })
      },
      goItyUrl: function () {
        hlUrlUtil.goTo('ityConfig', {
          ddtab: true
        })
      },
      goLcPlace: function () {
        hlUrlUtil.goTo('lcPlaceConfig', {
          ddtab: true
        })
      },
      goBusiness: function () {
        hlUrlUtil.goTo('businessConfig', {
          ddtab: true
        })
      },
      goFcsUrl: function () {
        hlUrlUtil.goTo('fcsConfig', {
          ddtab: true
        })
      },
      goItyUrl1: function () {
        hlUrlUtil.goTo('lcCutomFields', {
          ddtab: true,
          module: 'CUSTOMER'
        })
      },
      goItyUrl2: function () {
        hlUrlUtil.goTo('processMange', {
          ddtab: true
        })
      },
      goTo_Unit: function () {
        hlUrlUtil.goTo('costUnit', {
          ddtab: true
        })
      },
      getWorkConfig: function () {
        var self = this;
        hlhttp.get({
          url: 'configure/bpm_config/dict',
          success: function (res) {
            res.map(function (item, index) {
              item.flag = true;
              if (index == 1) {
                if (res[0].value == 0) {
                  item.flag = false
                }
              }
            })
            self.wrokList = res
          }
        })
      },
      // 获取足控配置字典code
      getRentConfigCode() {
        hlhttp.get({
          url: 'configure/dict',
          data: {
            "module_code": "ZUKN",
            "config_name": "ZK_PERFORM_SOON",
          },
          success: (res) => {
            this.rentConfigCode = res[0].dictCode
            this.rentConfigData = res[0].dictName
          }
        })
        hlhttp.get({
          url: 'configure/dict',
          data: {
            "module_code": "ZUKN",
            "config_name": "ZK_EXPIRE_SOON",
          },
          success: (res) => {
            this.rentConfigCodeEnd = res[0].dictCode
            this.rentConfigDataEnd = res[0].dictName
          }
        })
      },
      rentConfigSetting(val) {
        var self = this
        if (val == 'before') {
          if(this.rentConfigData<0 || this.rentConfigData%1 !== 0 || this.rentConfigData==''){
            hl.toast('请输入正整数')
            return
          }
          // 即将履约
          hlhttp.put({
            url: 'configure/user_defined_dict',
            data: {
              "module_code": "ZUKN",
              "config_name": "ZK_PERFORM_SOON",
              "dict_code": this.rentConfigCode,
              "value": this.rentConfigData,
              "dict_property": ""
            },
            success: function () {
              hl.toast('操作成功')
            }
          })
        }else{
          // 即将到期
          if(this.rentConfigDataEnd<0 || this.rentConfigDataEnd%1 !== 0 || this.rentConfigDataEnd==''){
            hl.toast('请输入正整数')
            return
          }
          if(this.rentConfigDataEnd%1 !== 0){
            hl.toast('请输入正整数')
            return
          }
          hlhttp.put({
            url: 'configure/user_defined_dict',
            data: {
              "module_code": "ZUKN",
              "config_name": "ZK_EXPIRE_SOON",
              "dict_code": this.rentConfigCodeEnd,
              "value": this.rentConfigDataEnd,
              "dict_property": ""
            },
            success: function () {
              hl.toast('操作成功')
            }
          })
        }

      },
      postWorkconfig: function (i, s) {
        var data = [];
        this.wrokList[i].value = s;
        var self = this;
        if (i == 0) {
          if (s == 0) {
            this.wrokList[1].value = s;
          }
        }
        this.wrokList.map(function (item, index) {
          data.push({
            code: item.code,
            value: item.value
          })
        })

        hlhttp.put({
          url: 'configure/bpm_config/dict',
          data: {
            config_info: JSON.stringify(data)
          },
          success: function () {
            hl.toast('操作成功')
            self.getWorkConfig()
          }
        })
      }
    },
    mounted: function () {
      this.getWorkConfig()
      this.geTintentBpmConfig()
      this.getRentConfigCode()
      this.getbillflow()
      if (this.quanxian.indexOf('c368') > -1) {
        this.getCostomer()
      }
    }
  })
}())